/*
 * UpdatePathsAction.java
 *
 * Created on 15 April 2007, 19:39
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.cardcopier.ui;

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JFrame;
import org.cardcopier.CardCopierModel;

/**
 *
 * @author Mark
 */
public class UpdatePathsAction extends AbstractAction {
    
    static final String INITIAL_PATH_SETUP = new String("Initial Path Setup");
    
    private final CardCopierModel cardCopierModel;
    private final JFrame updatePathsActionFrame;
    
    /** Creates a new instance of CopyAction */
    public UpdatePathsAction(CardCopierModel cardCopierModel, JFrame updatePathsActionFrame) {
        super("Update Paths");
        this.cardCopierModel = cardCopierModel;
        this.updatePathsActionFrame = updatePathsActionFrame;
    }

    public void actionPerformed(ActionEvent e) {
        UpdatePathsDialog dialog = new UpdatePathsDialog(updatePathsActionFrame, true, cardCopierModel.getFileLocationFactory());
        dialog.setLocationByPlatform(true);
        dialog.setSourceDirectory(cardCopierModel.getSourceDirectory());
        dialog.setDestinationDirectory(cardCopierModel.getDestinationBaseDir());
        dialog.setEvent(cardCopierModel.getEvent());
        if (INITIAL_PATH_SETUP.equals(e.getSource())) {
            dialog.guessEventDate();
        } else {
            dialog.setEventDate(cardCopierModel.getEventDate());
        }
        dialog.setVisible(true);
        if (dialog.userChoseOk()) {
            cardCopierModel.setPathDetails(dialog.getEventDate(), dialog.getEvent(), dialog.getSourceDirectory(), dialog.getDestinationDirectory());
        }
    }
    

}
